package driver

import (
	"errors"
	D "websocket_apn/define"
	"websocket_apn/driver/xddq"
)

// Transfer 接口定义
type Driver interface {
	Init()
	Send(m *D.Message) D.ErrorCode
	Receive(length int, msgId int32) (D.ErrorCode, *D.Message)
	Close()
}

//NewTransfer 构造函数
func NewDriver(param interface{}) (Driver, error) {
	if param == nil {
		return nil, errors.New("param is nil")
	}

	switch param.(type) {
	case xddq.Param:
		np := param.(xddq.Param)
		xd, err := xddq.NewXdDriver(np)
		if err != nil {
			return nil, err
		}

		return xd, nil

	default:
		return nil, errors.New("unknown param type")
	}
}
